var employees = [];
var firstnamequeue = ["Jack", "Jill", "Joseph", "Alice", "Chris", "Alicia", "Jared", "Daniel", "Jeremy","Robert"];
var lastnamequeue = ["Roelofs", "Smith", "Johnson", "Jones", "Moore", "Anderson", "Brown", "Martin", "Miller", "White", "Lee", "Young", "Baker", "Scott", "Nelson"];
var hiredEmployeeQueue = new Array();
var averageEfficiency = 0;
var numberOfEmployees = 0;
var wage = 6.50;


	


function generateEmployee(number) {
	var firstname, lastname, loyalty, efficiency;
	var count = 0;
	for (var i = 0; count < number; i++) {
		
		firstname = firstnamequeue[randomIntFromInterval(0, firstnamequeue.length - 1)];
		lastname = lastnamequeue[randomIntFromInterval(0, lastnamequeue.length - 1)];
		loyalty = randomIntFromInterval(1, 10);
		efficiency = randomIntFromInterval(1, 10);
		var obj = {};
		obj.Name = firstname + " " + lastname;
		obj.Loyalty = loyalty;
		obj.Efficiency = efficiency;
		if (employees.length == 0) {
			employees.push(obj);
			count = count + 1;
		} else {
			if (checkduplicate(obj.Name) == "No") {
				employees.push(obj);
				count = count + 1;
			}

		}

	}
}




function updateemployeeform() {
	var name = document.getElementById("emplyselect").value;
	objx(employees).each(function(item) {
		if (name == item.Name) {
			document.getElementById("name").value = item.Name;
			document.getElementById("loyalty").value = item.Loyalty;
			document.getElementById("efficiency").value = item.Efficiency;
		}
	});
}

function hireEmployee() {
	var name = document.getElementById("name").value;
	if (hiredEmployeeQueue.length < 1) {
		hiredEmployeeQueue.push(name);
		notify(name + " was hired","info");
		numberOfEmployees = numberOfEmployees + 1;
		averageEfficiency = getAverageEfficiency();
		document.getElementById("numemployee").value = hiredEmployeeQueue.length;
		//notify(averageEfficiency);
	} else {
		if (hiredEmployeeQueue.indexOf(name) == -1) {
			hiredEmployeeQueue.push(name);
			notify(name + " was hired","info");
			numberOfEmployees = numberOfEmployees + 1;
			averageEfficiency = getAverageEfficiency();
			document.getElementById("numemployee").value = hiredEmployeeQueue.length;
			//notify(averageEfficiency);
		} else {
			notify(name + " is already hired!","error");
		}

	}
}

function getAverageEfficiency() {
	var totalefficiency = 0;
	var efficiency = 0;
	if (numberOfEmployees != 0) {
		for (var i = 0; i < hiredEmployeeQueue.length; i++) {

			objx(employees).each(function(item) {
				if (hiredEmployeeQueue[i] == item.Name) {
					totalefficiency = (totalefficiency + item.Efficiency);
				}
			});

		}
		efficiency = totalefficiency / hiredEmployeeQueue.length;
	} else {
		efficiency = 0;
	}
	return efficiency;
}

function checkduplicate(name) {
	var duplicate = "No";
	objx(employees).each(function(item) {
		if (item.Name == name) {
			duplicate = "yes";
			return duplicate;

		}
	});
	return duplicate;
}

function employeeCost() {
	var cost = wage * employees.length;
	return cost;
}
